package Controller;

import java.util.ArrayList;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;

import DAO.TerminalDao;
import POJO.Terminal;

@Service
public class InitDataService implements ServletContextAware{

	@Autowired
	TerminalDao terminalDao;
	/**
	 * 把所有终端数据缓存到内存中
	 */
	public void setServletContext(ServletContext sc) {
		ArrayList<Terminal> terminals=terminalDao.returnAll();
		if(terminals!=null){
			for(Terminal t:terminals){
				sc.setAttribute("terminalCache"+t.getTerminalID()+t.getPassword(), t);
			}
		}

	}

}
